	#ifndef _ARRAY_H_
#define _ARRAY_H_
#include <cassert>

template<class T>
class Array
{
public:
	Array(int sz=50);
	Array(const Array<T>& a);
	~Array();
	Array<T>& operator =(const Array<T>& rhs);
	T& operator [](int i);
	const T& operator[](int i) const;
	operator T* ();
	operator const T* () const;
	int getSize() const;
	void resize(int sz);
	static void reversal( Array<T>& a);
private:
	int size;
	T* list;
};

template <class T>
Array<T>::Array(int sz)
{
	assert(sz >= 0);
	size = sz;
	list = new T[size];
}

template <class T>
Array<T>::Array(const Array<T>& a)
{
	size = a.size;
	this-> list = new T[size];
	for (int i = 0; i < size; ++i)
	{
		this->list[i]=a.list[i];
	}

}

template <class T>
Array<T>::~Array()
{
	size = 0;
	delete[] list;
}

template <class T>
Array<T>& Array<T>::operator =(const Array<T>& rhs)
{
	if (this!=&rhs)
	{
		if (this->size!=rhs.size)
		{
			delete[] list;
			size = rhs.size;
			list = new T[size];			
		}
		for (int i = 0; i < size; ++i)
		{
			list[i] = rhs.list[i];
		}
	}
	return *this;
}

template <class T>
T& Array<T>::operator[](int i)
{
	assert(i >= 0 && i <= size);
	return list[i];
}

template <class T>
const T& Array<T>::operator[](int i) const
{
	assert(i >= 0 && i <= size);
	return list[i];
}

template <class T>
Array<T>::operator T*()
{
	return list;
}

template <class T>
Array<T>::operator const T*() const
{
	return list;
}

template <class T>
int Array<T>::getSize() const
{
	return size;
}

template <class T>
void Array<T>::resize(int sz)
{
	assert(sz >= 0);
	if (sz!=size)
	{
		size = sz;
		T* newlist = new T[size];
		int n = size < sz ? size : sz;
		for (int i = 0; i < n; ++i)
		{
			newlist[i] = list[i];
		}
		delete[] list;
		list = newlist;
	}
	
}

template <class T>
void Array<T>::reversal(Array<T>& a)
{
	if (a.size != 1)
	{
		T temp;
		for (int i = 0; i < a.size / 2; ++i)
		{
			temp = a.list[i];
			a.list[i] = a.list[a.size - 1 - i];
			a.list[a.size - 1 - i] = temp;

		}

	}
}


#endif 
